import QtQuick 2.0


MouseArea{
    acceptedButtons: Qt.LeftButton | Qt.RightButton

    property int notOpen: 0
    property int opened: 1
    property int flaged: 2
    property int boomed: 3
    property int unknown: 4

    signal leftClicked()
    signal rightClicked()

    Rectangle{
        anchors.fill: parent
        anchors.margins: 5
        color: "#00ffffff"
        border.color: isMine(mineData) ? "red" : "#cca300"
        border.width: 1
        radius: 4

        Text{
            anchors.centerIn: parent
            color: "#cca300"
            font.family: "Arial"
            font.pixelSize: Math.min(parent.width,parent.height) * 3/4
//            text:(mineState === opened) ? nearMineCnt :
//                 (mineState === boomed) ? "☼" :
//                 (mineState === flaged) ? "☟" :
//                 (mineState === unknown) ? "?" : "";

            text: mineText(mineState,mineData);
        }
    }

    onClicked: {
        if (mouse.button === Qt.RightButton)
            rightClicked();
        else
            leftClicked();
    }

    function mineText(mineState,mineData){
        var text = "";

        switch(mineState)
        {
        case opened:
            if(mineData > 0)
                text = String("%1").arg(mineData);
        break;
        case boomed:text = "☼";break;
        case flaged:text = "☟";break;
        case unknown:text = "?";break;
        default:break;
        }
        return text;
    }

    function isMine(mineData){
        if(mineData < 0)
            return true;
        else
            return false;
    }
}
